home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October : Technology Seed / ATS Oct. '97.toast / Navigation Services SDK 1.0a6 / Examples / Sampler / Sampler ƒ / file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-31  |  17.9 KB  |  695 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        file.c
  3.  
  4.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #pragma segment DocSeg
  9.  
  10. #ifndef __STRINGS__
  11. #include <Strings.h>
  12. #endif
  13.  
  14. #ifndef __STDIO__
  15. #include <StdIO.h>
  16. #endif
  17.  
  18. #ifndef __FINDER__
  19. #include "Finder.h"
  20. #endif
  21.  
  22. #ifndef __NAVIGATION__
  23. #include "Navigation.h"
  24. #endif
  25.  
  26. #ifndef Common_Defs
  27. #include "Common.h"
  28. #endif
  29.  
  30. const long kPictHeaderSize = 512;
  31.  
  32. short ReadFile(Document* theDocument);
  33. short WriteFile(Document* theDocument);
  34. short WriteNewFile(Document* theDocument, FSSpec* newFileSpec);
  35.  
  36. pascal Boolean myFilterProc(AEDesc* theItem, void* info, NavContext context, NavCallBackUserData callBackUD);
  37.  
  38. extern Document* gDocumentList[kMaxDocumentCount];
  39.  
  40.  
  41. // *****************************************************************************
  42. // *
  43. // *    ReadFile()
  44. // *
  45. // *****************************************************************************
  46. short ReadFile(Document* theDocument)
  47. {    
  48.     long        count;
  49.     short        theResult;
  50.     char        buffer[256];
  51.     TextStyle    theStyle;
  52.  
  53.     SetCursor(*GetCursor(watchCursor));
  54.  
  55.     if (theDocument->theTE != NULL)
  56.         {
  57.         TESetSelect(0,(**(theDocument->theTE)).teLength,theDocument->theTE);
  58.         TEDelete(theDocument->theTE);
  59.  
  60.         if (theResult = SetFPos(theDocument->fRefNum,fsFromStart,0))
  61.             return theResult;
  62.  
  63.         do    {
  64.             count = 256;
  65.             theResult = FSRead(theDocument->fRefNum,&count,&buffer);
  66.             TEInsert(&buffer,count,theDocument->theTE);
  67.             }
  68.         while (theResult == noErr);
  69.  
  70.         if (theResult == eofErr)
  71.             theResult = noErr;
  72.     
  73.         TESetSelect(0,32767,theDocument->theTE);
  74.         theStyle.tsFont = 21;
  75.         theStyle.tsSize = 12;
  76.         TESetStyle(doFont + doSize,&theStyle,true,theDocument->theTE);
  77.         TESetSelect(0,0,theDocument->theTE);
  78.         }
  79.     else
  80.         {
  81.         short     result = noErr;
  82.         long    fileSize = 0;
  83.         long    headerSize = 0;
  84.         long    pictSize = 0;
  85.  
  86.         SetCursor(*(Cursor**)GetCursor(watchCursor));
  87.         
  88.         if (theResult = SetFPos(theDocument->fRefNum,fsFromStart,0))
  89.             return theResult;
  90.  
  91.         theResult = GetEOF(theDocument->fRefNum,&fileSize);
  92.         
  93.         theDocument->fPictLength = fileSize;
  94.         theDocument->fPictLength -= kPictHeaderSize;
  95.         theDocument->fPict = NewHandle(theDocument->fPictLength);
  96.         theDocument->fHeader = NewHandle(kPictHeaderSize);
  97.         if ((theDocument->fPict == NULL)||(theDocument->fPict == NULL))
  98.             {
  99.             SysBeep(5);
  100.             return memFullErr;
  101.             }
  102.         headerSize = kPictHeaderSize;
  103.         pictSize = theDocument->fPictLength;
  104.  
  105.         theResult = FSRead(theDocument->fRefNum,&headerSize,*theDocument->fHeader);
  106.         theResult = FSRead(theDocument->fRefNum,&pictSize,*theDocument->fPict);
  107.         }
  108.  
  109.     theDocument->dirty = false;
  110.  
  111.     if (theResult != noErr)
  112.         {
  113.         Str255 errorStr;
  114.         GetIndString(errorStr,rAppStringsID,sReadErr);
  115.         ParamText((ConstStr255Param)&errorStr,(ConstStr255Param)"\p",(ConstStr255Param)"\p",(ConstStr255Param)"\p");
  116.         NoteAlert(rGenericAlertID,0L);
  117.         }
  118.     return theResult;
  119. }
  120.  
  121.  
  122. // *****************************************************************************
  123. // *
  124. // *    WriteFile()
  125. // *
  126. // *****************************************************************************
  127. short WriteFile(Document* theDocument)
  128. {    
  129.     short    theResult;
  130.     long    length;
  131.     char*    bufPtr;
  132.  
  133.     SetCursor(*GetCursor(watchCursor));
  134.  
  135.     if (!theDocument->fRefNum)
  136.         return fnOpnErr;
  137.  
  138.     if (theResult = SetFPos(theDocument->fRefNum,fsFromStart,0))
  139.         return theResult;
  140.  
  141.     if (theDocument->theTE != NULL)
  142.         {
  143.         length = (**(theDocument->theTE)).teLength;
  144.         bufPtr = *((**(theDocument->theTE)).hText);
  145.  
  146.         theResult = FSWrite(theDocument->fRefNum,&length,bufPtr);
  147.         if (theResult == noErr)
  148.             theResult = SetEOF(theDocument->fRefNum,length);
  149.         }
  150.     else
  151.         {
  152.         long headerSize = kPictHeaderSize;
  153.         long pictSize = theDocument->fPictLength;
  154.  
  155.         theResult = FSWrite(theDocument->fRefNum,&headerSize,*theDocument->fHeader);
  156.         if (theResult == noErr)
  157.             {
  158.             theResult = FSWrite(theDocument->fRefNum,&pictSize,*theDocument->fPict);    
  159.             if (theResult == noErr)
  160.                 theResult = SetEOF(theDocument->fRefNum,headerSize+pictSize);
  161.             }
  162.         }
  163.  
  164.     return theResult;
  165. }
  166.  
  167.  
  168. // *****************************************************************************
  169. // *
  170. // *    WriteNewFile()
  171. // *
  172. // *****************************************************************************
  173. short WriteNewFile(Document* theDocument, FSSpec* newFileSpec)
  174. {    
  175.     short    theResult;
  176.     short    refNum = 0;
  177.  
  178.     SetCursor(*GetCursor(watchCursor));
  179.  
  180.     theResult = FSpOpenDF(newFileSpec,fsRdWrPerm,&refNum);
  181.     if (refNum != -1)
  182.         {
  183.         if (theResult = SetFPos(refNum,fsFromStart,0))
  184.             return(theResult);
  185.  
  186.         if (theDocument->theTE != NULL)
  187.             {
  188.             long    length;
  189.             char*    bufPtr;
  190.             length = (**(theDocument->theTE)).teLength;
  191.             bufPtr = *((**(theDocument->theTE)).hText);
  192.  
  193.             if (theResult = FSWrite(refNum,&length,bufPtr))
  194.                 return(theResult);
  195.  
  196.             theResult = SetEOF(refNum,length);
  197.             }
  198.         else
  199.             {
  200.             long headerSize = kPictHeaderSize;
  201.             long pictSize = theDocument->fPictLength;
  202.  
  203.             theResult = FSWrite(refNum,&headerSize,*theDocument->fHeader);
  204.             theResult = FSWrite(refNum,&pictSize,*theDocument->fPict);
  205.             
  206.             theResult = SetEOF(refNum,headerSize+pictSize);
  207.             }
  208.         theResult = FSClose(refNum);
  209.         }
  210.     return theResult;
  211. }
  212.  
  213.  
  214. // *****************************************************************************
  215. // *
  216. // *    DoNewDocument()
  217. // *
  218. // *****************************************************************************
  219. void DoNewDocument(Boolean newDocAsPICT)
  220. {    
  221.     Document* theDocument;
  222.     if (theDocument = NewDocument(newDocAsPICT))
  223.         ShowWindow(theDocument->theWindow);
  224. }
  225.  
  226.  
  227. // *****************************************************************************
  228. // *
  229. // *    DoOpenFile()
  230. // *
  231. // *****************************************************************************
  232. OSErr DoOpenFile(FSSpec* theFile, Boolean openAsPICT)
  233. {    
  234.     OSErr        result;
  235.     short        refNum;
  236.     Document*    theDocument = NULL;
  237.  
  238.     result = FSpOpenDF(theFile,fsRdWrPerm,&refNum);
  239.     if ((result == fLckdErr) || (result == afpAccessDenied))
  240.         result = FSpOpenDF(theFile,fsRdPerm,&refNum);
  241.  
  242.     if (result == noErr)
  243.         {
  244.         theDocument = NewDocument(openAsPICT);
  245.         if (theDocument != NULL)
  246.             {
  247.             theDocument->fRefNum = refNum;
  248.             
  249.             result = ReadFile(theDocument);
  250.                 
  251.             SetWTitle(theDocument->theWindow,theFile->name);
  252.             SizeDocWindow(theDocument);
  253.  
  254.             AdjustScrollBar(theDocument);
  255.             ShowWindow(theDocument->theWindow);    
  256.             }
  257.         else
  258.             {
  259.             FSClose(refNum);
  260.             result = memFullErr;
  261.             }
  262.         }
  263.     else
  264.         {
  265.         Str255 errorStr;
  266.         if (result == vLckdErr || result == afpVolLocked || result == wPrErr || result == permErr)
  267.             GetIndString(errorStr,rAppStringsID,sWriteToBusyFileErr);
  268.         else
  269.             if (result == opWrErr)
  270.                 GetIndString(errorStr,rAppStringsID,sBusyOpen);
  271.             else
  272.                 GetIndString(errorStr,rAppStringsID,sOpeningErr);
  273.         ParamText((ConstStr255Param)&errorStr,(ConstStr255Param)"\p",(ConstStr255Param)"\p",(ConstStr255Param)"\p");
  274.         NoteAlert(rGenericAlertID,0L);
  275.         }
  276.     return result;
  277. }
  278.  
  279.  
  280. // *****************************************************************************
  281. // *
  282. // *    myFilterProc()
  283. // *
  284. // *    If user choose "none" for 'open' resoure filtering, this routine could
  285. // *    affect the filter if used!
  286. // *
  287. // *****************************************************************************
  288. pascal Boolean myFilterProc(AEDesc* theItem, void* info, NavContext /*context*/, NavCallBackUserData /*callBackUD*/)
  289. {
  290.     OSErr                     theErr = noErr;
  291.     Boolean                 display = false;
  292.     NavFileOrFolderInfo*    theInfo;
  293.  
  294.     if (theItem->descriptorType == typeFSS)
  295.         {
  296.         theInfo = (NavFileOrFolderInfo*)info;    
  297.         if (((theInfo->isFolder) && (theInfo->visible)) ||
  298.             ((theInfo->fileAndFolder.fileInfo.finderInfo.fdFlags & kIsAlias) != 0))
  299.             display = true;            // item is a visible folder (normal or aliased)
  300.         else
  301.             switch (theInfo->fileAndFolder.fileInfo.finderInfo.fdType)
  302.                 {
  303.                 case 'TEXT':
  304.                 case 'PICT':
  305.                     display = true;
  306.                     break;
  307.                 default:
  308.                     display = false;
  309.                     break;
  310.                 }
  311.         }
  312.     return display;
  313. }
  314.  
  315.  
  316. // *****************************************************************************
  317. // *
  318. // *    myEventProc()    
  319. // *
  320. // *****************************************************************************
  321. pascal void myEventProc(const NavEventCallbackMessage callBackSelector, 
  322.                         NavCBRecPtr callBackParms, 
  323.                         NavCallBackUserData callBackUD)
  324. {
  325.     WindowPtr    pWindow = NULL;
  326.     Document**    docList;
  327.     Document*    theDoc = NULL;
  328.     short         index = 0;
  329.  
  330.     if (callBackUD != 0)
  331.         switch (callBackSelector)
  332.             {
  333.             case kNavCBEvent:
  334.                 {
  335.                 docList = (Document**)callBackUD;
  336.                 if (docList != NULL)
  337.                     switch (callBackParms->eventData.event->what)
  338.                         {
  339.                         case nullEvent:
  340.                             break;
  341.                             
  342.                         case updateEvt:
  343.                             pWindow = (WindowPtr)callBackParms->eventData.event->message;
  344.                             theDoc = docList[index];
  345.                             if (theDoc != NULL)
  346.                                 {
  347.                                 while ((theDoc->theWindow != pWindow) && (docList[index] != NULL))
  348.                                     {
  349.                                     index++;
  350.                                     theDoc = docList[index];
  351.                                     }
  352.                                 theDoc = docList[index];
  353.                                 if (theDoc != NULL)
  354.                                     UpdateWindow(theDoc);
  355.                                 }
  356.                             break;
  357.  
  358.                         case activateEvt:
  359.                             break;
  360.  
  361.                         default:
  362.                             break;
  363.                         }
  364.                 break;
  365.                 }
  366.             }
  367. }
  368.  
  369.  
  370. // *****************************************************************************
  371. // *
  372. // *    DoOpenDocumentTheOldWay()
  373. // *
  374. // *****************************************************************************
  375. OSErr DoOpenDocumentTheOldWay()
  376. {    
  377.     OSErr theErr = noErr;
  378.     //••
  379.     return theErr;
  380. }
  381.  
  382.  
  383. // *****************************************************************************
  384. // *
  385. // *    DoOpenDocument()
  386. // *
  387. // *****************************************************************************
  388. OSErr DoOpenDocument()
  389. {    
  390.     NavReplyRecord        theReply;
  391.     NavDialogOptions    dialogOptions;
  392.     OSErr                theErr = noErr;
  393.     NavTypeListHandle    openList = NULL;
  394.     long                count = 0;
  395.     NavEventUPP            eventUPP = NewNavEventProc(myEventProc);
  396.     NavObjectFilterUPP    filterUPP = NewNavObjectFilterProc(myFilterProc);
  397.     
  398.     // default behavior for browser and dialog:
  399.     theErr = NavGetDefaultDialogOptions(&dialogOptions);
  400.  
  401.     GetIndString((unsigned char*)&dialogOptions.clientName,rAppStringsID,sApplicationName);
  402.     
  403.     openList = (NavTypeListHandle)GetResource(kOpenRsrcType,kOpenRsrcID);
  404.     if ((openList != NULL)&&(ResError() == noErr))
  405.         HLock((Handle)openList);
  406.  
  407.     dialogOptions.preferenceKey = kOpenPrefKey;
  408.  
  409.     dialogOptions.dialogOptionFlags += kDontAutoTranslate;    // we will do the translation ourselves later:
  410.  
  411.     theErr = NavGetFile(NULL,    // use system's default location
  412.                         &theReply,
  413.                         &dialogOptions,
  414.                         eventUPP,
  415.                         NULL,    // no custom previews
  416.                         filterUPP,
  417.                         (NavTypeListHandle)openList,
  418.                         (NavCallBackUserData)&gDocumentList);
  419.  
  420.     DisposeRoutineDescriptor(eventUPP);
  421.     DisposeRoutineDescriptor(filterUPP);
  422.  
  423.     if (theReply.validRecord && theErr == noErr)
  424.         {
  425.         // since we allow for multiple objects to be returned,
  426.         // grab the target FSSpecs from 'theReply.fileRef' list for opening:    
  427.         FSSpec    finalFSSpec;    
  428.         AEDesc     resultDesc;
  429.         FInfo    fileInfo;
  430.  
  431.         // in the case we didn't want built in translation:
  432.         if ((dialogOptions.dialogOptionFlags & kDontAutoTranslate) != 0)
  433.             if (theReply.translationNeeded)
  434.                 {
  435.                 // if we didn't want built in translation it was for the following reasons:
  436.                 //        1) we wanted to do it ourselves
  437.                 //        2) or we wanted to defer it    
  438.                 // things to remember if auto-translation is turned off:
  439.                 //         1) the AEDesc list contains the original file specs the user had chosen.
  440.                 //        2) the 'fileTranslation' field for each object that needs translation has filled in for you.
  441.                 
  442.                 // put your own code here to perform your own translation.
  443.                 // - or -
  444.                 // we can simply call this to perform the translation manually:
  445.                 Str255     errorStr;
  446.  
  447.                 if ((theErr = NavTranslateFile(&theReply,kNavTranslateCopy)) != noErr)
  448.                     {
  449.                     if (theErr == vLckdErr || theErr == afpVolLocked || theErr == wPrErr || theErr == permErr)
  450.                         GetIndString(errorStr,rAppStringsID,sTranslationLockedErr);
  451.                     else
  452.                         GetIndString(errorStr,rAppStringsID,sTranslationErr);
  453.                     ParamText((ConstStr255Param)&errorStr,(ConstStr255Param)"\p",(ConstStr255Param)"\p",(ConstStr255Param)"\p");
  454.                     NoteAlert(rGenericAlertID,0L);
  455.                     }
  456.                 }
  457.  
  458.         if (theErr == noErr)
  459.             {
  460.             // we are ready to open the document(s), grab information about each file for opening:
  461.             theErr = AECountItems(&(theReply.selection),&count);
  462.             for (long index=1;index<=count;index++)
  463.                 {
  464.                 resultDesc.dataHandle = 0L;
  465.                 theErr = AEGetNthDesc(&(theReply.selection),index,typeFSS,NULL,&resultDesc);
  466.                 if (theErr == noErr)
  467.                     {
  468.                     BlockMoveData(*resultDesc.dataHandle,&finalFSSpec,sizeof(FSSpec));
  469.                 
  470.                     // decide if the doc we are opening is a 'PICT' or 'TEXT':
  471.                     theErr = FSpGetFInfo(&finalFSSpec,&fileInfo);
  472.                     if (theErr == noErr)
  473.                         {
  474.                         if (fileInfo.fdType == kFileType)
  475.                             (void)DoOpenFile(&finalFSSpec,false);
  476.                         else
  477.                             if (fileInfo.fdType == kFileTypePICT)
  478.                                 (void)DoOpenFile(&finalFSSpec,true);
  479.                             else
  480.                                 {
  481.                                 // error:
  482.                                 // if we got this far, the document is a type we can't open and
  483.                                 // (most likely) built-in translation was turned off.
  484.                                 // You can alert the user that this returned selection or file spec
  485.                                 // needs translation.
  486.                                 }
  487.                         }
  488.                     theErr = AEDisposeDesc(&resultDesc);
  489.                     }
  490.                 }
  491.             }
  492.         
  493.         theErr = NavDisposeReply(&theReply);    // clean up after ourselves    
  494.         }
  495.  
  496.     if (openList != NULL)
  497.         {
  498.         HUnlock((Handle)openList);
  499.         ReleaseResource((Handle)openList);
  500.         }
  501.  
  502.     return theErr;
  503. }
  504.  
  505.  
  506. // *****************************************************************************
  507. // *
  508. // *    SaveACopyDocumentTheOldWay()
  509. // *
  510. // *****************************************************************************
  511. OSErr SaveACopyDocumentTheOldWay(Document* /*theDocument*/)
  512. {
  513.     //••
  514.     return noErr;
  515. }
  516.  
  517.  
  518. // *****************************************************************************
  519. // *
  520. // *    SaveACopyDocument()
  521. // *
  522. // *****************************************************************************
  523. OSErr SaveACopyDocument(Document* theDocument)
  524. {    
  525.     OSErr                theErr = noErr;
  526.     NavReplyRecord        theReply;
  527.     NavDialogOptions    dialogOptions;
  528.     NavEventUPP            eventUPP = NewNavEventProc(myEventProc);
  529.     Str255                docTitle;
  530.     OSType                fileTypeToSave;
  531.  
  532.     GetIndString((unsigned char*)&dialogOptions.clientName,rAppStringsID,sApplicationName);
  533.     
  534.     // default behavior for browser and dialog:
  535.     theErr = NavGetDefaultDialogOptions(&dialogOptions);
  536.  
  537.     GetWTitle(theDocument->theWindow,docTitle);
  538.     p2cstr((StringPtr)docTitle);
  539.     sprintf((char*)dialogOptions.savedFileName,(char*)"%s copy",docTitle);
  540.     c2pstr((Ptr)dialogOptions.savedFileName);
  541.         
  542.     if (theDocument->theTE != NULL)    // which document type is it?
  543.         fileTypeToSave = kFileType;
  544.     else
  545.         fileTypeToSave = kFileTypePICT;
  546.  
  547.     dialogOptions.preferenceKey = kSavePrefKey;
  548.  
  549.     theErr = NavPutFile(NULL,    // use system's default location
  550.                         &theReply,
  551.                         &dialogOptions,
  552.                         eventUPP,
  553.                         fileTypeToSave,
  554.                         kFileCreator,
  555.                         (NavCallBackUserData)&gDocumentList);
  556.  
  557.     DisposeRoutineDescriptor(eventUPP);
  558.  
  559.     if ((theReply.validRecord)&&(theErr == noErr))
  560.         {
  561.         FSSpec    finalFSSpec;    
  562.         AEDesc     resultDesc;    
  563.         resultDesc.dataHandle = 0L;
  564.         
  565.         // retrieve the returned selection:
  566.         // since only 1 selection is possible, we get the first AEDesc:
  567.         theErr = AEGetNthDesc(&(theReply.selection),1,typeFSS,NULL,&resultDesc);
  568.         if (theErr == noErr)
  569.             {
  570.             BlockMoveData(*resultDesc.dataHandle,&finalFSSpec,sizeof(FSSpec));
  571.  
  572.             if (theReply.replacing)
  573.                 theErr = FSpDelete(&finalFSSpec);
  574.             if (theErr == noErr)
  575.                 {
  576.                 theErr = FSpCreate(&finalFSSpec,kFileCreator,fileTypeToSave,smSystemScript);
  577.                 if (theErr == noErr)
  578.                     {
  579.                     theErr = WriteNewFile(theDocument,&finalFSSpec);    // use this document's data to write to our new copy
  580.                     if (theErr == noErr)
  581.                         {
  582.                         // translation may be needed for file we are saving a copy of,
  583.                         // when you save a copy, you should always "translate in place":
  584.                         theErr = NavCompleteSave(&theReply,kNavTranslateInPlace);
  585.                         }
  586.                     }
  587.                 }
  588.             else
  589.                 if (theErr == fBsyErr)
  590.                     {
  591.                     Str255 errorStr;
  592.                     GetIndString(errorStr,rAppStringsID,sReadErr);
  593.                     ParamText((ConstStr255Param)&errorStr,(ConstStr255Param)"\p",(ConstStr255Param)"\p",(ConstStr255Param)"\p");
  594.                     NoteAlert(rGenericAlertID,0L);
  595.                     }
  596.             }
  597.         theErr = NavDisposeReply(&theReply);
  598.         }
  599.     
  600.     return theErr;
  601. }
  602.  
  603.  
  604. // *****************************************************************************
  605. // *
  606. // *    DoSaveDocument()
  607. // *
  608. // *****************************************************************************
  609. short DoSaveDocument(Document* theDocument)
  610. {
  611.     if (!theDocument)
  612.         return false;
  613.  
  614.     if (theDocument->fRefNum)
  615.         {
  616.         if (WriteFile(theDocument))
  617.             {
  618.             SysBeep(5);
  619.             return false;
  620.             }
  621.         else
  622.             theDocument->dirty = false;
  623.         return true;
  624.         }
  625.     else
  626.         {
  627.         //•• need SaveACopy replica here: return(SaveAsDocument(theDocument));
  628.         //•• also, these routines should return OSErr!
  629.         return true;
  630.         }
  631. }
  632.  
  633.  
  634. // *****************************************************************************
  635. // *
  636. // *    DoRevertDocument()
  637. // *
  638. // *****************************************************************************
  639. void DoRevertDocument(Document* theDocument)
  640. {    
  641.     if (!theDocument)
  642.         return;
  643.  
  644.     if (theDocument->fRefNum)
  645.         {
  646.         OSErr                         theErr = noErr;
  647.         NavEventUPP                    eventUPP = NewNavEventProc(myEventProc);
  648.         NavAskDiscardChangesResult     reply;
  649.         Str255                         theName;
  650.  
  651.         GetWTitle(theDocument->theWindow,(unsigned char*)&theName);
  652.         theErr = NavAskDiscardChanges(    theName,
  653.                                         &reply,
  654.                                         eventUPP,
  655.                                         (NavCallBackUserData)&gDocumentList);
  656.         
  657.         DisposeRoutineDescriptor(eventUPP);
  658.  
  659.         switch (reply)
  660.             {
  661.             case askDiscardChanges:        
  662.                 if (ReadFile(theDocument))
  663.                     SysBeep(5);
  664.                 break;
  665.  
  666.             case askDiscardChangesCancel:
  667.                 break;
  668.             }
  669.         }
  670. }
  671.  
  672. // *****************************************************************************
  673. // *
  674. // *    DoRevertDocumentTheOldWay()
  675. // *
  676. // *****************************************************************************
  677. void DoRevertDocumentTheOldWay(Document* theDocument)
  678. {    
  679.     Str255 theName;
  680.  
  681.     if (!theDocument)
  682.         return;
  683.  
  684.     if (theDocument->fRefNum)
  685.         {
  686.         GetWTitle(theDocument->theWindow,(unsigned char*)&theName);
  687.         ParamText((ConstStr255Param)&theName,(ConstStr255Param)"\p",(ConstStr255Param)"\p",(ConstStr255Param)"\p");
  688.         if (Alert(rRevertID,0L) == 1)
  689.             if (ReadFile(theDocument))
  690.                 SysBeep(5);
  691.         }
  692. }
  693.  
  694.  
  695.